/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgp;

//import byzantine.views.View;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author rpathan
 */
public class ByzantineModel {

    public static final String NO_TARGET_SELECTED = "No Target Selected";
    public static final String COMMANDER = "Loyal Commander";
    public static final String COMMANDER_REBEL = "Rebel Commander";
    public static final String GENERAL = "Loyal General";
    public static final String GENERAL_REBEL = "Rebel General";
   /* public static final int MAX_GENERALS = 10;
    public static final int MIN_GENERALS_TO_RUN = 2;
    private List<View> observers;
    private ArrayList<General> generals;
    private ArrayList<Integer> generalIndices;
    private General selectedGeneral;
    private boolean selectedGeneralChanged;
    private boolean simulationStatusChanged;
    private boolean commanderStatusChanged;
    private boolean numGeneralsChanged;
    private boolean simulationRunning;
    private boolean hasCommander;

    public ByzantineModel() {
        observers = new LinkedList<View>();
        generals = new ArrayList<General>();

        generalIndices = new ArrayList<Integer>();
        for (int i = 0; i < MAX_GENERALS; i++) {
            generalIndices.add(new Integer(i));
        }

        selectedGeneral = null;
        selectedGeneralChanged = false;

        simulationStatusChanged = false;
        commanderStatusChanged = false;
        numGeneralsChanged = false;

        simulationRunning = false;
        hasCommander = false;
    }

    public void addGeneral(String type) {

        if (generalIndices.size() > 0) {
            if (type.equals(COMMANDER) || type.equals(COMMANDER_REBEL)) {
                hasCommander = true;
                commanderStatusChanged = true;
            }
            General g = new General(generalIndices.remove(0), type);
            generals.add(g);
            numGeneralsChanged = true;
            notifyObservers();
        } else {
            System.err.println("Error: No general slots remaining");
        }
    }

    public void removeGeneral(General g) {

        if (generalIndices.size() < MAX_GENERALS) {
            int ID = g.getID();
            String type = g.getType();
            if (type.equals(COMMANDER) || type.equals(COMMANDER_REBEL)) {
                hasCommander = false;
                commanderStatusChanged = true;
            }
            generalIndices.add(ID);
            numGeneralsChanged = true;
            generals.remove(g);
            notifyObservers();
        }
    }

    public int getNumGenerals() {
        return generals.size();
    }

    public General getSelectedGeneral() {
        return selectedGeneral;
    }

    public void setSelectedGeneral(General g) {
        if (g == selectedGeneral) {
            return;
        }

        selectedGeneral = g;
        selectedGeneralChanged = true;
        notifyObservers();
    }

    public boolean hasSelectedGeneralChanged() {
        return selectedGeneralChanged;
    }

    public boolean hasNumGeneralsChanged() {
        return numGeneralsChanged;
    }

    public boolean hasSimulationStatusChanged() {
        return simulationStatusChanged;
    }

    public boolean hasCommanderStatusChanged() {
        return commanderStatusChanged;
    }

    public boolean isSimulationRunning() {
        return simulationRunning;
    }

    public boolean hasCommander() {
        return hasCommander;
    }
    
    public void reset() {
        generals.clear();
        generalIndices.clear();
        for (int i = 0; i < MAX_GENERALS; i++) {
            generalIndices.add(new Integer(i));
        }

        selectedGeneral = null;
        selectedGeneralChanged = true;

        numGeneralsChanged = true;
        simulationStatusChanged = true;
        commanderStatusChanged = true;

        simulationRunning = false;
        hasCommander = false;
        notifyObservers();
    }

    public void addObserver(View view) {
        observers.add(view);
    }

    private void notifyObservers() {
        for (View observer : observers) {
            observer.valueChanged();
        }
        selectedGeneralChanged = false;
        numGeneralsChanged = false;
        simulationStatusChanged = false;
        commanderStatusChanged = false;
    }*/
}
